//
//  TcpServerManage.swift
//  iDev
//
//  Created by lbxia on 2021/9/18.
//

import Foundation
import CocoaAsyncSocket


class ClientModel {
    
    enum ClientConnectType : Int {
        case mouse = 0
        case keyboard = 1
        case mouseAndKeyboard = 2
        case fileSync = 3
        case all = 4
    }
    
    var clientSocket : GCDAsyncSocket?
    
    //客户端名称
    var clientName : String?
    
    //iphone,ipad,android, android pad ,mac, windows
    var clientType : String?
    
    var clientOSVersion: String?
    
    //
    var token: String?
    //通信密钥，采用XXX 加密
    var secretKey : String?
}

/*
 
 登录连接端口，然后返回对应的mouse,keyboard, filesync 对应的服务器端口
 
 mouse 、keyboard控制
 
 数据字节定义
 控制类型,功能类型,数据长度,数据
 
 鼠标 0xA0,0xA1开头均为鼠标
 //鼠标左键, 按下并抬起
 0xA0,0x00,0x01,0x00
 //鼠标左键按下
 0xA0,0x00,0x01,0x01
 //鼠标左键抬起
 0xA0,0x00,0x01,0x02
 
 
 //鼠标右键点击,其实不需要数据，保存协议完整性
 0xA0,0x01,0x01,0x00
 
 //鼠标移动,4个字节偏移坐标值,负值 表示 左 上，正值表示右 下，注意网络字节序
 0xA0,0x03,0x08,dxdy
 
 
 
 
 //键盘 0xA2,0xA3开头均为键盘
 按键输入 128--255为扩展字符
 0xA2,0x00,0x01,键值
 
 //功能键
 0xA2,0x01,len,功能键值(8个字节表示一个功能键键)
 
 
 
 //系统快捷功能,0xA3开头
 //打开Lanchpad
 0xA3,0x00,0x01,0x00
 
 //打开mission control
 0xA3,0x01,0x01,0x00
 
 //多屏幕切换 显示右边一个
 0xA3,0x02,0x01,0x00
 
 //多屏幕切换 显示左边边一个
 0xA3,0x02,0x01,0x01

 //显示桌面，触摸板扩散效果
 0xAE,0x03,0x01,0x00
 
 //隐藏所有app,显示桌面
 0xA3,0x03,0x01,0x01
 
 //显示当前app所有窗口 command+向下方向键
 0xA3,0x04,0x01,0x00
 
 
 0xA3,0x04,0x01,0x00
 
 
 
 filesysn
 手机屏幕直播
 
 
 //tcp心跳
 0xFF,0xEE,0x10,0x00
 
 */

class TcpServerManage {
    
    var serverSocket : GCDAsyncSocket?
    
    var localIp : String?
    
    //默认16213,监听失败自动递增 范围[0,65535]
    var listenPort : UInt16 = 16213
    
    var clients: [GCDAsyncSocket : ClientModel]?
}
